<?php
	$user_obj = new user();
	$city_obj = new city();
	$admin_obj = new admin();
	$api_pos_auth_obj = new api_pos_auth();
	$action_ary = array(
		'userinfo' => 'api_user_act_userinfo',//收银机查询用户信息接口
		'api_reg' => 'api_user_act_api_reg',//用户注册接口。用于收银机注册 暂不用
		'point_minus'=>'api_user_act_point_minus',//扣除会员积分接口
		'point_add'=>'api_user_act_point_add',//增加会员积分接口 消费

		'sms_send'=>'user_act_sms_send',//发送短信验证码

		'change_state'=>'user_act_change_state',//更改会员状态


		'reg'=>'user_act_reg',//网页用户注册
		'unique_user'=>'user_act_unique_user',//网页用户注册用户唯一性检测
		'login'=>'user_act_login',//用户登录
		'exit'=>'user_act_exit',//用户登录
		'edit'=>'user_act_edit',//用户信息修改
		'phone_activate'=>'user_act_phone_activate',//用户帐号激活
		'find_pwd'=>'user_act_find_pwd',//用户密码找回
		'discount_add'=>'user_act_discount_add',//添加、编辑折扣信息
	);

	//执行函数
	if($action && ($fun = $action_ary[$action])){
		$fun();
	}
	/*************************action********************/



	
	
	/**
	* 用户退出
	* @author xiezhihui 2014-5-8 15:40:42
	*/
	function user_act_exit(){
		destroy_session();
		echo_json(array('state'=>true,'msg'=>1402));
	}

	/**
	* 用户密码找回
	* @author xiezhihui 2014-6-3 14:55:10
	*/
	function user_act_find_pwd(){
		global $user_obj,$_site,$sms_obj;
		$phone = request('mobile',false,true);
		$sms_code = request('sms_code',false,true);
		$s = $user_obj->check_user_unique($phone);
		if($s['phone_auth']=='2'){
			echo_json(array('msg'=>1432,'state'=>false));
		}
		if(!is_mobile($phone)){
			echo_json(array('msg'=>306,'state'=>false));
		}
		if(!$s){
			echo_json(array('msg'=>1035,'state'=>false));
		}
		$sms_check = $user_obj->sms_data(array('phone'=>$phone,'type'=>3));

		if($sms_code!=$sms_check['check_code']){ ///输入的验证码和短息验证码不匹配
			echo_json(array('msg'=>1424,'state'=>false));
		}

		$sms_expires = $_site->site_config['site']['sms_expires']+((int)$sms_check['create_time']);//短信有效时间(秒)

		if(time()>$sms_expires){ ///验证码不再有效期内
			echo_json(array('msg'=>1423,'state'=>false));
		}
		$password = request('password');
		$repassword = request('repassword');
		preg_match('/^\d{6,20}/',$password,$matches);
		if(!$matches){
			echo_json(array('msg'=>307,'state'=>false));
		}
		if($password!=$repassword){
			echo_json(array('msg'=>1011,'state'=>false));
		}
		if(character_length_ch($password)<6 || character_length_ch($password)>=20 || !$password){
			echo_json(array('msg'=>307,'state'=>false));
		}
		$state = $user_obj->edit_user(array('password'=>md5($password)),$s['id']);
		if($state){
			echo_json(array('msg'=>1430,'state'=>true));
		}
		echo_json(array('msg'=>1431,'state'=>false));
	}
	/**
	* 用户帐号激活
	* @author xiezhihui 2014-6-3 13:47:32
	*/
	function user_act_phone_activate(){
		global $user_obj,$_site,$sms_obj;
		$phone = request('mobile',false,true);
		$sms_code = request('sms_code',false,true);
		$s = $user_obj->check_user_unique($phone);
		if($s['phone_auth']=='1'){
			echo_json(array('msg'=>1429,'state'=>false));
		}
		if(!is_mobile($phone)){
			echo_json(array('msg'=>306,'state'=>false));
		}
		if(!$s){
			echo_json(array('msg'=>1035,'state'=>false));
		}
		$sms_check = $user_obj->sms_data(array('phone'=>$phone,'type'=>2));

		if($sms_code!=$sms_check['check_code']){ ///输入的验证码和短息验证码不匹配
			echo_json(array('msg'=>1424,'state'=>false));
		}

		$sms_expires = $_site->site_config['site']['sms_expires']+((int)$sms_check['create_time']);//短信有效时间(秒)

		if(time()>$sms_expires){ ///验证码不再有效期内
			echo_json(array('msg'=>1423,'state'=>false));
		}
		$state = $user_obj->edit_user(array('phone_auth'=>1),$s['id']);
		if($state){
			echo_json(array('msg'=>1427,'state'=>true));
		}
		echo_json(array('msg'=>1428,'state'=>false));
	}


	/**
	* 发送短信验证码
	*
	*/
	function user_act_sms_send(){
		global $user_obj,$sms_obj,$_site;
		$phone = request('phone',false,true);
		$user_info = $user_obj->check_user_unique($phone);

		if(!is_mobile($phone)){
			echo_json(array('msg'=>1418,'state'=>false));
		}

		$type = (int)request('type',false,true);
		$check_code = mt_rand(100000,999999);
		$create_time = time();
		switch ($type){
			case 1://注册帐号
				if($user_info){
					echo_json(array('msg'=>1034,'state'=>false));
				}
				$smsTmp = 1;//短信模版
				$data=compact('phone','type','check_code','create_time');
			break;
			case 2://激活帐号
				if(!$user_info){
					echo_json(array('msg'=>1035,'state'=>false));
				}
				if($user_info['phone_auth']=='1'){
					echo_json(array('msg'=>1429,'state'=>false));
				}
				$smsTmp = 0;//短信模版
				$data=compact('phone','type','check_code','create_time');
			break;
			case 3://密码找回
				if(!$user_info){
					echo_json(array('msg'=>1035,'state'=>false));
				}
				$smsTmp = 2;//短信模版
				$data=compact('phone','type','check_code','create_time');
			break;
			default:
			echo_json(array('msg'=>1420,'state'=>false));
		}
		$sms_check = $user_obj->sms_data(array('phone'=>$phone,'type'=>$type));//获取
		if($sms_check) $data['id']=$sms_check['id'];
		$sms_retry_time = $_site->site_config['site']['sms_retry_time']+((int)$sms_check['create_time']);//短信失效时间(秒)
		$time=time();
		if($time<=$sms_retry_time){ //短信重复发送有时间间隔
			echo_json(array('time'=>($sms_retry_time-$time),'state'=>false,'msg'=>1425));
		}
		$s = $user_obj->sms_auto_ins_up($data);
		if($s){
			$sms_s = $sms_obj->send_msg($phone,$check_code,$smsTmp);
			$sms_check = $user_obj->sms_data(array('phone'=>$phone,'type'=>$type));//获取
			$sms_retry_time = $_site->site_config['site']['sms_retry_time']+((int)$sms_check['create_time']);//短信失效时间(秒)
			$time = $sms_retry_time-time();
			if($sms_s){
				echo_json(array('time'=>$time,'msg'=>1422,'state'=>true));
			}
			echo_json(array('time'=>$time,'msg'=>1421,'state'=>false));
		}
		echo_json(array('msg'=>1421,'state'=>false));
	}


	/**
	* 用户登录
	* @author xiezhihui 2014-5-6 10:46:59
	*/
	function user_act_login(){
		global $user_obj;
		$mobile = request('mobile');
		if(!is_mobile($mobile)){
			echo_json(array('state'=>false,'msg'=>1418));
		}
		$password = request('password');
		preg_match('/^\d{6,20}/',$password,$matches);
		if(!$matches){
			echo_json(array('state'=>false,'msg'=>1417));
		}
		$password=md5($password);
		$userinfo=$user_obj->out_login($mobile,$password);
		if(!$userinfo){
			echo_json(array('state'=>false,'msg'=>1009));
		}
		if($userinfo['state']==2){
			echo_json(array('state'=>false,'msg'=>1404));
		}

		if($userinfo['phone_auth']!='1'){
			echo_json(array('state'=>false,'msg'=>1426));
		}
		if(!$userinfo['phone']){
			echo_json(array('state'=>false,'msg'=>1419));
		}

		if($userinfo['phone']==$mobile && $userinfo['password']==$password){
			unset($userinfo['password']);
			unset($userinfo['point']);
			unset($userinfo['total_point']);
			set_session('user',serialize($userinfo)."");

			echo_json(array('state'=>true,'msg'=>1403));
		}

		echo_json(array('state'=>true,'msg'=>1403));
	}
	/**
	* 收银机状态修改
	* @author xiezhihui 14-04-10 05:23
	*/
	function user_act_change_state(){
		global $admin_obj,$user_obj;
		$state=request('state',false,true);
		if(!$state){
			location_msg(L(1003));
		}
		$id=request('id',false,true);
		if(!$id){
			location_msg(L(1003));
		}
		$admin_info = $admin_obj->out_cookie();
		if(!$admin_info){
			location_msg(L(1017));
		}
		$data=compact('state');
		$s = $user_obj->user_update($id,$data);
		if(!$s){
			location_msg(L(1003));
		}
		location_msg(L(1004));
	}
	/**
	* 收银机查询会员信息
	* @author xiaxin 2014-04-09
	*/
	function api_user_act_userinfo(){
		global $user_obj,$api_pos_auth_obj;
		$mobile = request('mobile',false,true);//手机号
		$clientkey = request('clientkey');//客户端key

		if(!$mobile){
			api_echo_json(array('code'=>204));
		}
		if(!$api_pos_auth_obj->check_pos_clientkey($clientkey)){
			api_echo_json(array('code'=>203));
		}
		$token = $api_pos_auth_obj->url_sign_auth(&$_GET);//自动验证url及重复提交

		if(!$user_obj->check_user_unique($mobile)){
			api_echo_json(array('code'=>304));
		}
		$res = $user_obj->get_user_by_phone($mobile);

		if(!$res){
			api_echo_json(array('code'=>305));
		}

		$max_discount=10;
		$vip_name='普通会员';

		//$vip_discount = $user_obj->get_vip_discount_arr();
		$vip_discount = user_fun_get_vip_discount_by_city($res['area'],$res['total_point']);
		if($vip_discount){
			$max_discount = $vip_discount['discount'];
			$vip_name = $vip_discount['vip_type'];
		}
		$msg = array(
			'mobile'=>$res['phone'],
			'point'=>$res['point'],
			'city'=>$res['area'],
			'city_name'=>$res['city_name'],
			'vipname'=>$res['name'],
			'sex'=>$res['sex'],
			'email'=>$res['email'],
			'viptype'=>$vip_name,
			'sale'=>$max_discount
		);

		api_echo_json($msg);


	}
	/**
	* 收银机注册用户
	* @author xiezhihui 14-04-09 10:29
	*
	*/
	function api_user_act_api_reg(){
		global $user_obj,$api_pos_auth_obj,$sms_obj;
		$clientkey = request('clientkey');


		$row = $api_pos_auth_obj->check_pos_clientkey($clientkey);
		if(!$row){
			api_echo_json(array('code'=>203,));
		}
		$data = user_fun_share_reg();
		$s=$user_obj->reg_user($data);
		if($s){
			api_echo_json(array('code'=>0,'id'=>$s));
		}
		api_echo_json(array('code'=>310));
	}


	/**
	* 注册用户
	* @author xiezhihui 14-04-09 10:29
	*
	*/
	function user_act_reg(){
		global $user_obj,$sms_obj;
		/*$yzm=request('yzm');
		$auth_code_object = new auth_code();
		if(!$auth_code_object->check($yzm)) {
			echo_json(array('msg'=>1001,'state'=>false));
		}*/



		$data = user_fun_share_reg();

		$s=$user_obj->reg_user($data);
		if($s){
			echo_json(array('msg'=>311,'state'=>true));
		}
		api_echo_json(array('msg'=>310,'state'=>false));
	}


	/**
	* 用户信息修改
	* @author xiezhihui 2014-5-8 15:41:02
	*/
	function user_act_edit(){
		global $user_obj;
		$yzm=request('yzm');
		$auth_code_object = new auth_code();
		if(!$auth_code_object->check($yzm)) {
			echo_json(array('msg'=>1001,'state'=>false));
		}
		$user_info = $user_obj->_session_userinfo();
		if(!$user_info){
			echo_json(array('state'=>false,'msg'=>1411));
		}
		$name = urldecode(request('name'));
		if($name){
			if(character_length_ch($name)>10){
				echo_json(array('msg'=>308,'state'=>false));
			}

		}
		$area = request('area',false,true);
		if(!$area){
			echo_json(array('msg'=>309,'state'=>false));

		}
		$sex = request('sex',false,true);
		$age = request('age',false,true);
		preg_match('/^[1-9]\d{0,1}$/',$age,$matches);//只能购买1-99个
		if(!$matches){
			echo_json(array('state'=>false,'msg'=>'3028'));
		}
		$age = strtotime('-'.$age.' year');
		$data = compact('name','area','sex','age');
		$s=$user_obj->edit_user($data,$user_info['id']);
		if($s){
			echo_json(array('msg'=>1018,'state'=>true));
		}
		echo_json(array('msg'=>1019,'state'=>false));
	}


	/**
	* 用户唯一性检测
	* @author xiezhihui 2014-5-8 15:41:30
	*/
	function user_act_unique_user(){
		global $user_obj;
		$phone = request('param');
		$type = request('type');
		$s = $user_obj->check_user_unique($phone);
		if($type=='activate'){
			if(!$s){
				echo '该用户不存在';
			}else{
				echo 'y';
			}
			return;
		}

		if($s){
			echo '该用户已存在';
		}else{
			echo 'y';
		}
	}

	/**
	* 收银机会员扣除积分接口
	* @author xiaxin 2014-04-09
	*
	*/
	function api_user_act_point_minus(){
		global $user_obj,$api_pos_auth_obj;
		$clientkey = request('clientkey');//客户端的key
		if(!$client_info = $api_pos_auth_obj->check_pos_clientkey($clientkey)){
			api_echo_json(array('code'=>203));
		}
		$token = $api_pos_auth_obj->url_sign_auth(&$_GET);//自动验证url及重复提交
		$mobile = request('mobile',false,true);//手机号
		if(!$user_obj->check_user_unique($mobile)){
			api_echo_json(array('code'=>304));
		}
		$password = request('password');
		if(!$user_info = $user_obj->out_login($mobile,$password)){
			api_echo_json(array('code'=>201));
		}
		if($user_info['state']==2){//账号被禁用
			api_echo_json(array('code'=>305));
		}
		$point = request('point',false,true);//积分
		if(!$point || preg_match('/[^\d]/',$point,$matches)){
			api_echo_json(array('code'=>402));
		}
		if($user_info['point'] < $point){
			api_echo_json(array('code'=>401));
		}
		$type = request('type',false,true,false,1);//积分类型 1消费积分
		if($type!=1){
			//这里强制为消费积分。防止参数不合法
			api_echo_json(array('code'=>403));
		}
		$obj = request('obj');//物品编号（也可以是品名或套餐名） 用收银机传入。
		if(!$obj){
			api_echo_json(array('code'=>404));
		}
		//$from = request('from',false,true,false,1);//来自什么消费 1-收银机 2-积分商城
		$from = 1;//这里值提供了给收银机接口使用$clientkey 就必须为1
		//$handle_time = false;//提交时间 扣除处理时间必须时时
		$handle_time = time();
		$point_log_info = array(
			'type' => $type,
			'obj' => $obj,
			'from' => $from,
			'handle_time' => $handle_time,
			'point' => $point,
			'pos_id' => $client_info['id'],
		);
		$res = $user_obj->user_point_minus($user_info['id'],$point,$point_log_info);
		if(!$res){
			api_echo_json(array('code'=>401));
		}
		$user_info = $user_obj->out_login($mobile,$password);
		api_echo_json(array('point'=>$user_info['point'], 'code'=>0));
	}

	/**
	* 增加会员的积分 比如消费rmb获得
	* @author xiezhihui 14-04-09 02:19
	*/
	function api_user_act_point_add(){
		global $user_obj,$api_pos_auth_obj,$city_obj,$sms_obj;
		$clientkey = request('clientkey');
		$row = $api_pos_auth_obj->check_pos_clientkey($clientkey);
		if(!$row){
			api_echo_json(array('code'=>203,));
		}
		$token = $api_pos_auth_obj->url_sign_auth(&$_GET);//自动验证url及重复提交
		$phone = request('mobile',false,true);
		if(!is_mobile($phone)){
			api_echo_json(array('code'=>306,));
		}
		$point = request('point',false,true);
		preg_match('/^[1-9]\d{0,10}$|0/',$point,$matches);
		if(!$matches){
			api_echo_json(array('code'=>402,));
		}
		$money = request('money',false,true);//消费金额 xiaxin 2014-06-03
		if(!preg_match('/^(([1-9]\d*)|0)(\.\d{1,2})?$/',$money)){
			api_echo_json(array('code'=>415,));
		}
		$type = request('type',false,true,false,2);//默认是消费获得赠送积分
		if($type!=2){
			api_echo_json(array('code'=>403,));
		}
		$obj = request('obj');//物品
		if(!$obj){
			api_echo_json(array('code'=>404,));
		}
		$time = request('time',false,true);//积分消费处理时间
		if(!$time){
			$time=time();
		}

		$data['type']=$type;
		$data['handle_time']=$time;
		$data['create_time']=time();
		$data['from']=1;
		$data['point']=$point;
		$data['obj']=$obj;
		$data['pos_id']=$row['id'];//收银机id
		$data['point']=$point;
		$data['money']=$money;//消费金额
		$res = $user_obj->check_user_unique($phone);
		if($res['state']==2){
			api_echo_json(array('code'=>305));
		}
		if($res){ //当用户手机号码存在的时候 写入积分

			$data['phone']=$phone;
			$s=$user_obj->add_point($data);
			$data['uid']=$res['id'];
			if($s){
				$user_obj->user_point_log($data);
				$tmp = $user_obj->check_user_unique($phone);
				$sms_obj->send_msg($phone,array(0=>$row['name'],1=>$money,2=>$tmp['point']),3);//添加积分成功后发送短信
				api_echo_json(array('code'=>0,'point'=>$tmp['point']));
			}
			api_echo_json(array('code'=>405,));

		}
		//当手机号码不存在的时候 先隐示注册在增加积分
		$data['phone']=$phone;
		$zx_city=$city_obj->zx_city();
		$res_row=$user_obj->reg_user(array( 'phone'=>$phone,'password'=>md5(substr($phone,-6)),'area'=>$row['area'],'create_time'=>time() ));
		//$res_row=$user_obj->reg_user(array( 'phone'=>$phone,'password'=>md5(substr($phone,-6)),'province'=>substr($row['area'],0,2).'0000','city'=>in_array(substr($row['area'],0,2).'0000',$zx_city)?substr($row['area'],0,2).'0000':substr($row['area'],0,4).'00','area'=>$row['area'] ));
		if($res_row){
			$data['uid']=$res_row;
			$s=$user_obj->add_point(array('point'=>$point,'phone'=>$phone));
			if($s){
				$user_obj->user_point_log($data);
				$tmp = $user_obj->check_user_unique($phone);
				$sms_obj->send_msg($phone,array(0=>$row['name'],1=>$money,2=>$tmp['point']),3);//添加积分成功后发送短信 xiaxin 2014-06-03
				api_echo_json(array('code'=>0,'point'=>$tmp['point']));
			}
			api_echo_json(array('code'=>405,));

		}
		api_echo_json(array('code'=>405,));

	}

	function user_act_discount_add(){
		global $user_obj,$admin_obj;
		$msg = array('state'=>false,'msg'=>1415);
		if(!$admin_obj->out_cookie()){
			echo_json($msg);
		}
		$id = request('id',false,true);
		$province = request('province',false,true);
		$city = request('city',false,true);
		$area = request('area',false,true);
		$config = request('config');
		if(preg_match('/[^\x{4e00}-\x{9fa5}a-zA-Z0-9:,\.]/u',$config)){
			$msg['msg'] = 1433;
			echo_json($msg);
		}
		$data['config'] = $config;
		if($area){
			$data['city'] = $area;
		}elseif($city){
			$data['city'] = $city;
		}elseif($province){
			$data['city'] = $province;
		}else{
			$data['city'] = 0;
		}
		if($user_obj->discount_check_city_unique($data['city'],$id)){
			$msg['msg']= 1434;
			echo_json($msg);
		}
		if($id){
			$result = $user_obj->discount_edit($data,$id);
		}else{
			$result = $user_obj->discount_add($data);
		}
		if(!$result){
			$msg['msg'] = 1003;
			echo_json($msg);
		}
		$msg = array('state'=>true,'msg'=>1004);
		echo_json($msg);
	}



	/************************ function ******************/
	/**
	* 网页和收银机共用参数处理方法 目前收银机没有
	* @author xiezhihui 14-04-09 02:37
	*/
	function user_fun_share_reg(){
		global $user_obj,$api_pos_auth_obj,$sms_obj,$_site;

		$phone = request('mobile',false,true);
		$sms_code = request('sms_code',false,true);
		if(!is_mobile($phone)){
			echo_json(array('msg'=>306,'state'=>false));
		}


		$sms_check = $user_obj->sms_data(array('phone'=>$phone,'type'=>1));

		if($sms_code!=$sms_check['check_code']){ ///输入的验证码和短息验证码不匹配
			echo_json(array('msg'=>1424,'state'=>false));
		}

		$sms_expires = $_site->site_config['site']['sms_expires']+((int)$sms_check['create_time']);//短信有效时间(秒)

		if(time()>$sms_expires){ ///验证码不再有效期内
			echo_json(array('msg'=>1423,'state'=>false));
		}
		$s = $user_obj->check_user_unique($phone);
		if($s){
			echo_json(array('msg'=>301,'state'=>false));
		}
		$password = request('password');
		$repassword = request('repassword');
		preg_match('/^\d{6,20}/',$password,$matches);
		if(!$matches){
			echo_json(array('msg'=>307,'state'=>false));
		}
		if($password!=$repassword){
			echo_json(array('msg'=>1011,'state'=>false));
		}
		if(character_length_ch($password)<6 || character_length_ch($password)>=20 || !$password){
			echo_json(array('msg'=>307,'state'=>false));
		}
		$email = request('email',false,false,true);
		if($user_obj->check_user_unique_email($email)){
			echo_json(array('msg'=>302,'state'=>false));
		}
		$name = urldecode(request('name'));
		if($name){
			if(character_length_ch($name)>10){
				echo_json(array('msg'=>308,'state'=>false));
			}

		}
		$area = request('area',false,true);
		if(!$area){
			echo_json(array('msg'=>309,'state'=>false));

		}

		$sex = request('sex',false,true);
		$data = compact('phone','password','name','email','area','sex');
		if($data['sex']===false) unset($data['sex']);
		if($data['email']===false) unset($data['email']);
		if($data['name']===false) unset($data['name']);
		$data['password']=md5($data['password']);
		$data['create_time']=time();
		$data['phone_auth']=1;//注册后是通过了手机验证的则该帐号就被手机激活
		return $data;
	}

	/**
	* 获取会员用户列表
	*
	* @param mixed $data
	* @param mixed $page
	* @param mixed $pagesize
	*/
	function user_fun_get_user_list($data,$page=1,$pagesize=10){
		global $user_obj;
		return $user_obj->get_user_list($data,$page,$pagesize);
	}

	/**
	* 返回vip用户打折信息
	*
	* @param mixed $total_point
	* @return mixed
	*/
	function user_fun_get_vip_config($total_point){
		$total_point = (int)$total_point;
		global $user_obj;
		$vip_discount = $user_obj->get_vip_discount_arr();
		if($vip_discount){
			$max_discount = 0;
			foreach($vip_discount as $v){
				if($total_point >= $v['point']){
					$max_discount = $v['discount'];
					$vip_name = $v['name'];
					break;
				}
			}
		}else{
			$max_discount=10;
			$vip_name='普通会员';
		}
		return array('discount'=>$max_discount,'vip_type'=>$vip_name);
	}
	/**
	* 根据id获取用户信息
	* @author xiezhihui 14-04-12 09:05
	* @param mixed $id
	*/
	function user_fun_user_info($id){
		global $user_obj;
		if(!$id){
			return false;
		}
		return $user_obj->get_user_by_id($id);
	}
	/**
	* 获取积分日志信息
	* @author xiezhihui 14-04-12 10:22
	*
	* @param mixed $data
	* @param mixed $page
	* @param mixed $pagesize
	*/
	function user_fun_get_logs_list($data,$page=1,$pagesize=10){
		global $user_obj;
		return $user_obj->get_logs_list($data,$page,$pagesize);
	}
	/**
	* 获取单个积分日志信息
	*
	* @param mixed $id
	*/
	function user_fun_get_logs_info($id){
		global $user_obj;
		if(!$id){
			return false;
		}
		return $user_obj->get_logs_info($id);
	}
	/**
	* 获取用户登录信息 没登录返回flase
	*
	*/
	function user_fun_get_user_login_info(){
		global $user_obj;
		return $user_obj->_session_userinfo();
	}

	/**
	* 折扣信息列表
	* @author xiaxin 2014-06-06
	* @param mixed $data
	* @param mixed $page
	* @param mixed $pagesize
	* @return array
	*/
	function user_fun_get_vip_discount_list($data,$page=1,$pagesize=10){
		global $user_obj;
		$result = $user_obj->discount_list($data,$page,$pagesize);
		if($result['rows']){
			foreach($result['rows'] as $k=>$v){
				$discount = explode(',',$v['config']);
				foreach($discount as $key=>$val){
					$discount_info = explode(':',$val);
					$discount[$key] = $discount_info;
				}
				$result['rows'][$k]['config']=$discount;
			}
		}
		return $result;
	}

	/**
	* 根据id取得折扣信息
	*
	* @param mixed $id
	* @return array
	*/

	function user_fun_get_vip_discount_info($id){
		global $user_obj;
		$result = $user_obj->discount_get_by_id($id);
		//if($result){
//			$discount = explode(',',$result['config']);
//			foreach($discount as $k=>$v){
//				$discount_info = explode(':',$v);
//				$discount[$key] = $discount_info;
//			}
//			$result['config'] = $discount;
//		}
		return $result;
	}

	/**
	* 根据会员的区域id取得折扣信息
	*
	* @param mixed $city
	* @param int $tatal_point
	* @return array
	*/
	function user_fun_get_vip_discount_by_city($city,$total_point){
		global $user_obj;
		if(!is_numeric($total_point)){
			return false;
		}
		$discount = array('discount'=>10,'vip_type'=>'普通会员');
		$result = $user_obj->discount_get_by_city($city);
		if($result){
			$config = explode(',',$result['config']);
			foreach($config as $k=>$v){
				$discount_info = explode(':',$v);
				if($total_point >= $discount_info[0]){
					$discount = array('discount'=>$discount_info[2],'vip_type'=>$discount_info[1]);
					break;
				}
			}
		}
		return $discount;
	}
?>
